package vn.edu.hcmut.cse.ai.search.problems.blocksworld;

import vn.edu.hcmut.cse.ai.infrastructure.Action;
import vn.edu.hcmut.cse.ai.infrastructure.ActionCost;
import vn.edu.hcmut.cse.ai.infrastructure.Actions;
import vn.edu.hcmut.cse.ai.infrastructure.GoalTest;
import vn.edu.hcmut.cse.ai.infrastructure.Node;
import vn.edu.hcmut.cse.ai.infrastructure.Problem;
import vn.edu.hcmut.cse.ai.search.problems.blocksworld.actiontype.BlocksWorldActionType;

public class BlocksWorldProblem extends Problem{

    public BlocksWorldProblem(Object initialState, Actions actions, GoalTest goalTest, ActionCost actionCost) {
        super(initialState, actions, goalTest, actionCost);
    }

    @Override
    public Node getChildNode(Node node, Action action) {
        BlocksWorldAction blocksWorldAction = (BlocksWorldAction) action;
        BlocksWorldState blocksWorldState = new BlocksWorldState((BlocksWorldState)node.getState());
        
        BlocksWorldActionType blocksWorldActionType = blocksWorldAction.getActionType();
        blocksWorldState.insertPredicates(blocksWorldActionType.getAddList());
        blocksWorldState.removePredicates(blocksWorldActionType.getRemoveList());
        
        double stepCost = this.actionCost.actionCost(node.getState(), blocksWorldState, action);
        Node returnNode = new Node(blocksWorldState, node, blocksWorldAction, stepCost);
        return returnNode;
    }
    
}
